/*
 * @Description: In User Settings Edit
 * @Author: your name
 * @Date: 2019-10-11 15:07:27
 * @LastEditTime: 2019-10-11 16:24:10
 * @LastEditors: Please set LastEditors
 */
//错误分类
//已知型错误
//未知错误
//这是一个全局异常捕获
const {HttpException}= require('../core/http-exception')
const catchError= async(ctx,next)=>{
    try {
        await next();
    }catch(error){
        //http status code 2xx,4xx,5xx
        //message
        //error_code详细的错误，开发者自己定义的.
        //request_url
        if(error instanceof HttpException){
            ctx.body={
                msg:error.msg,
                errorCode:error.errorCode,
                request:`${ctx.path} with ${ctx.method}`
            }
            ctx.status=error.code;
        }
    }
}
module.exports=catchError;